<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//类型控制器	
class TypeController extends CommonController{
	private $model;
	public function __init()
	{
		parent::__init();
		$this->model=new \Common\Model\Type;
	}
	public function index()
	{
		$data=$this->model->get();
		foreach ($data as $k => $v) {
			$data[$k]['type_tid']=Db::table('type_att')->where("type_tid={$v['tid']}")->count();
		}
		View::with('data',$data);
		View::make();
	}
	public function add()
	{
		if (IS_POST) {
			if ($this->model->store(Q('post.tname'))) {
				View::success('添加成功',U('index'));
			}
			//否则添加失败
			View::error($this->model->getError());
		}
		View::make();
	}
	public function del()
	{
		$tid=Q('get.tid');
		$this->model->where("tid={$tid}")->delete();
		View::success('删除成功',U('index'));
	}
	public function edit()
	{
		$tid=Q('get.tid');
		if (IS_POST) {
			if (!$this->model->edit($tid)) View::error($this->model->getError());
			View::success('修改成功',U('index'));
		}
		$olddata=$this->model->where("tid={$tid}")->find();
		View::with('olddata',$olddata);
		View::make();
	}
}
?>